package com.zxj.schoolxianyu.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zxj.schoolxianyu.dao.conversationDao;
import com.zxj.schoolxianyu.dao.messageDao;
import com.zxj.schoolxianyu.entity.conversation;
import com.zxj.schoolxianyu.entity.message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class chatService {
    @Autowired(required = false)
    private messageDao messageDao;
    @Autowired(required = false)
    private conversationDao conversationDao;

    public String chat(message message) {
        java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
        message.chatedate = currentDate;
        messageDao.insert(message);
        conversation c = new conversation();
        c.lastmessage = message.message;
        EntityWrapper<conversation> c1 = new EntityWrapper<>();
        c1.eq("conversationid",message.conversationid);
        conversationDao.update(c,c1);
        return "success";
    }
}
